## Set WD and load packages/files

rm(list = ls())

library(SetMethods)

## Import data 
dataraw <- read.csv("Raw scores.csv", header = T, row.names = 1)
head(dataraw)

##### Calibration of resources #####
HIGHRES <- calibrate(dataraw$RESraw, type = "fuzzy", 
                     thresholds = c(60000, 1000000, 5000000))
HIGHRES <- round(HIGHRES, digits = 2)
HIGHRES

# XY plot
plot(dataraw$RESraw, HIGHRES)
abline(h=0.5)

# Histogram
hist(HIGHRES, main = "Distribution of RES", xlab = "RES (calibrated)")

#### Calibration of expert opinion (politicisation) #####
SALcal <- calibrate(dataraw$EXPERT.SAL, type = "fuzzy", 
                    thresholds = c(2, 3, 4))
SALcal <- round(SALcal, digits = 2)
SALcal

# XY plot
plot(dataraw$EXPERT.SAL, SALcal)
abline(h = 0.5)

# Histogram
hist(SALcal, main = "Distribution of expert opinion on POL", 
     xlab = "SAL (calibrated)")

##### Calibration of media salience #####
# Load data files # 
SALUKraw <- read.csv("SALRAW UK.csv", header = T, row.names = 1)
head(SALUKraw)

SALITraw <- read.csv("SALRAW IT.csv", header = T, row.names = 1)
head(SALITraw)

# Calibrate UK
SALUKcal <- calibrate(SALUKraw$SALRAW, method = "direct", 
                   type = "fuzzy",
                   thresholds = c(0, 0.01, 0.1))
SALUKcal <- round(SALUKcal, digits = 2)
head(SALUKcal)

# XY plot and histogram
plot(SALUKraw$SALRAW, SALUKcal)
abline(h = 0.5)

hist(SALUKcal, main = "Distribution of media salience (UK)",
     xlab = "UK media salience (cal)")


# Calibrate IT
SALITcal <- calibrate(SALITraw$SALRAW, method = "direct", 
                   type = "fuzzy", 
                   thresholds = c(0, 0.08, 0.2))
SALITcal <- round(SALITcal, digits = 2)
head(SALITcal)

# XY plot and histogram
plot(SALITraw$SALRAW, SALITcal)
abline(h = 0.5)

hist(SALITcal, main = "Distribution of media salience (IT)", 
     xlab = "IT media salience (cal)")